
use "$replication\data\for_event_elecXroad.dta", clear

global cluster "sd_code"

global post_terms 4
global pre_terms 5


global depvar "icw_irrigation"

gegen group=group(year_road year_elec s_code)

drop elec road
gen elec=(year>=year_elec)
gen road=(year>=year_road)

qui sum ${depvar} if year_elec==year_road
local m_depvar=r(mean)
local N=r(N)
unique sd_code if  year_elec==year_road

qui sum ${depvar} if year_elec<year_road
local m_depvar=r(mean)
local N=r(N)
unique sd_code if  year_elec<year_road


qui sum ${depvar} if year_elec>year_road
local m_depvar=r(mean)
local N=r(N)
unique sd_code if  year_elec>year_road


*** E: Estimating impact of both at the sametime
did_multiplegt_dyn $depvar group year road if  year_elec==year_road ,  effects(5) cluster(sd_code) trends_nonparam(s_code) graph_off
estimates store E
global elecXroad_1_b=e(Av_tot_effect)
global elecXroad_1_se=e(se_avg_total_effect)

*** A: Estimating impact of electricity only

did_multiplegt_dyn $depvar group year elec if year_road>year_elec & road==0 ,  effects($post_terms) cluster(sd_code) trends_nonparam(s_code) graph_off
estimates store A
global elec_2_b=e(Av_tot_effect)
global elec_2_se=e(se_avg_total_effect)


*** B: Estimating impact of road after electricity
did_multiplegt_dyn $depvar group year road if year_road>year_elec & elec==1 ,  effects($post_terms) cluster(sd_code) trends_nonparam(s_code) graph_off
global elecXroad_2_b=e(Av_tot_effect)
global elecXroad_2_se=e(se_avg_total_effect)



*** C: Estimating impact of road only
did_multiplegt_dyn $depvar group year road if year_elec>year_road & elec==0,  effects($post_terms) cluster(sd_code) trends_nonparam(s_code) graph_off
global road_3_b=e(Av_tot_effect)
global road_3_se=e(se_avg_total_effect)


*** D: Estimating impact of electricity after road
did_multiplegt_dyn $depvar group year elec if  year_elec>year_road & road==1,  effects($post_terms) cluster(sd_code) trends_nonparam(s_code) graph_off
global elecXroad_3_b=e(Av_tot_effect)
global elecXroad_3_se=e(se_avg_total_effect)


global comp_1_b=${elecXroad_1_b}-${elec_2_b}-${road_3_b}
global comp_2_b=${elecXroad_2_b}-${road_3_b}
global comp_3_b=${elecXroad_3_b}-${elec_2_b}


global comp_1_se=sqrt((${elecXroad_1_se})^2+(${elec_2_se})^2+(${road_3_se})^2)
global comp_2_se=sqrt((${elecXroad_2_se})^2+(${road_3_se})^2)
global comp_3_se=sqrt((${elecXroad_3_se})^2+(${elec_2_se})^2)

forval i=1/3 {
	disp "Implied interaction:  ${comp_`i'_b} (${comp_`i'_se})"
}


